<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<!-- 组合式API watch -->

<body>
<div id="app">

</div>
</body>
<script src="js/vue.js"></script>
<script>

    // 引用类型的计算属性 get 与 set
    const app = Vue.createApp({
        setup(props, context) {
            const {ref, reactive, watch, toRefs} = Vue;
            let eduObject = reactive({brand: 'Java', site: 'http://localhost'});

            const {brand, site} = toRefs(eduObject);

            // 侦听器- 侦听引用类型的变化, 这里需要使用 箭头函数
            watch( () => eduObject.brand, (currentBrand, oldBrand)=>{
                // 相应的业务处理
                console.log("现在的值：", currentBrand);
                console.log("之前的值：", oldBrand);
            });

            return {
                brand, site
            }
        },
        template: `
          <div>
              <div>
                品牌：<input type="text" v-model="brand"/>
                <p>输入的品牌是：{{ brand }}</p>
              </div>
              <div>
                网址：<input type="text" v-model="site"/>
                <p>输入的品牌是：{{ site }}</p>
              </div>
          </div>
        `
    }).mount("#app");

</script>

</html>
